package com.tianhui.consignortwofei.mvp.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.entity.region.AreaInfo;
import com.fgs.common.entity.region.CityInfo;
import com.fgs.common.entity.region.ProvinceInfo;
import com.fgs.common.widget.PlaceSelectView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.mvp.model.enty.SourcePathInfo;

import butterknife.BindView;

/**
 * @author fgs
 * @date 2020/8/31
 * @description
 **/
public class SelectSourcePathActivity extends BaseActivity {

    @BindView(R.id.activity_select_source_path_placeSelectView)
    PlaceSelectView mPlaceSelectView;

    private int mPathType;
    private SourcePathInfo mPathInfo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_select_source_path;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public String getToolbarTitle() {
        return "选择地址";
    }

    @Override
    public void init() {

        mPathInfo = new SourcePathInfo();

        Bundle bundle = getIntent().getExtras();
        if (bundle != null && !bundle.isEmpty()) {
            mPathType = bundle.getInt(KeyValue.KEY_TYPE);
        }

        mPlaceSelectView.setOnPlaceConditionSelectListener(new PlaceSelectView.OnPlaceConditionSelectListener() {
            @Override
            public void onSelect(String province, String city, String area) {

            }

            @Override
            public void onSelect(ProvinceInfo provinceInfo, CityInfo cityInfo, AreaInfo areaInfo) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(provinceInfo.name);
                if (areaInfo != null && !TextUtils.isEmpty(cityInfo.name)) {
                    stringBuilder.append("，");
                    stringBuilder.append(cityInfo.name);
                    mPathInfo.placecity = cityInfo.name;
                    mPathInfo.placecitycode = cityInfo.code;
                }
                if (areaInfo != null && !TextUtils.isEmpty(areaInfo.name) && !areaInfo.name.equals("全市")) {
                    stringBuilder.append("，");
                    stringBuilder.append(areaInfo.name);
                    mPathInfo.placecounty = areaInfo.name;
                }

                mPathInfo.address = stringBuilder.toString();
                mPathInfo.placeprovince = provinceInfo.name;
                if (TextUtils.isEmpty(mPathInfo.placecitycode)) {
                    mPathInfo.placecitycode = provinceInfo.code;
                }

                Intent intent = new Intent();
                intent.putExtra(KeyValue.KEY_PATH_INFO, mPathInfo);
                setResult(mPathType, intent);
                finish();
            }
        });

    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }
}
